#include "calendar.h"
#include <time.h>
#include <stdio.h>
#include <sys/time.h>

void test_calendar()
{
    time_t seconds = time(NULL);
    printf("epoch seconds:%d\n", seconds);

    struct timeval timev;
    gettimeofday(&timev, NULL);
    printf("epoch seconds:%d,micro seconds:%ld\n", timev.tv_sec, timev.tv_usec);

    char *time_str = ctime(&seconds);
    printf("ctime str:%s\n", time_str);

    struct tm time_gm;
    struct tm *gm_ptr = gmtime(&timev.tv_sec);
    time_gm = *gm_ptr;
    printf("gmtime tm properties: year=%d,month=%d,day=%d,hour=%d,min=%d,sec=%d\n", 
        time_gm.tm_year, time_gm.tm_mon, time_gm.tm_mday, time_gm.tm_hour, time_gm.tm_min, time_gm.tm_sec);
    
    struct tm time_local = *localtime(&seconds);
    printf("localtime tm properties: year=%d,month=%d,day=%d,hour=%d,min=%d,sec=%d\n", 
        time_gm.tm_year, time_gm.tm_mon, time_gm.tm_mday, time_gm.tm_hour, time_gm.tm_min, time_gm.tm_sec);
    
    printf("gmtime str:%s\n", asctime(&time_gm));
    printf("localtime str:%s\n", asctime(&time_local));

    char time_pretty_str[32];
    strftime(time_pretty_str, sizeof(time_pretty_str), "%F %T", &time_local);
    printf("strftime str:%s\n", time_pretty_str);

}
